package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.Type;
import com.bwie.service.TypeService;
import com.bwie.mapper.TypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xueji
 * @description 针对表【type】的数据库操作Service实现
 * @createDate 2024-09-02 11:27:42
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type>
        implements TypeService {


    @Autowired
    private TypeMapper typeMapper;

    public List<Type> treeList() {
        List<Type> typeList = typeMapper.selectList(null);


        setChildren((long) 0, typeList);
        return typeList;
    }

    private List<Type> setChildren(Long id, List<Type> typeList) {

        List<Type> listTwo = typeList.stream().filter(type -> type.getTestId().intValue() == id.intValue()).collect(Collectors.toList());

        listTwo.stream().map(type -> {
            type.setChildren(setChildren(type.getId(), typeList));
            return type;
        }).collect(Collectors.toList());

        return listTwo;
    }
}




